#备忘录模式
class RoleStateMemento():
    def __init__(self,vit,atk,def0):
        self.m_vit=vit  #生命力
        self.m_atk=atk  #攻击力
        self.m_def=def0 #防御力

    def setVitality(self,vit):
        self.m_vit=vit
        
    def getVitality(self):
        return self.m_atk        

    def setAttack(self,atk):
        self.m_atk=atk
        
    def getAttack(self):
        return self.m_atk
    
    def setDefense(self,def0):
        self.m_def=def0

    def getDefense(self):
        return self.m_def       

class GameRole():
    def __init__(self,vit=None,atk=None,def0=None):
        self.m_vit=vit  #生命力
        self.m_atk=atk  #攻击力
        self.m_def=def0 #防御力
        
    def  SaveState(self):
        return  RoleStateMemento(self.m_vit,self.m_atk,self.m_def)
   
    def  RecoveryState(self,memento):
        print('恢复后:')
        self.m_vit=memento.getVitality() #生命力
        self.m_atk=memento.getAttack()   #攻击力
        self.m_def=memento.getDefense()  #防御力
        
    def GetInitState(self):
        self.m_atk = self.m_def = self.m_vit = 100
    
    def Fight(self):
        print('大战:')
        self.m_atk = self.m_def = self.m_vit = 0
        
    def StateDisplay(self):
        print('角色当前状态：')
        print('体力',self.m_vit)
        print('攻击力',self.m_atk)
        print('防御力',self.m_def)
        
#Caretaker，管理者，此处为游戏角色管理类
class RoleStateCaretaker():
    def __init__(self):
        self.m_memento=None
        
    def   setMemento(self,memento):
        self.m_memento=memento
        
    def   getMemento(self):
        return  self.m_memento

if __name__ == '__main__':
    #大战Boss前
    lixiaoyao =GameRole()
    lixiaoyao.GetInitState()
    lixiaoyao.StateDisplay()
    #保存进度
    stateAdmin =  RoleStateCaretaker()
    stateAdmin.setMemento(lixiaoyao.SaveState())
    #大战Boss时，损耗严重
    lixiaoyao.Fight()
    lixiaoyao.StateDisplay()
    #恢复之前状态
    lixiaoyao.RecoveryState(stateAdmin.getMemento())
    lixiaoyao.StateDisplay()
    
    
    